// API响应基础类型
export enum ResponseStatus {
  SUCCESS = "success",
  ERROR = "error",
  WARNING = "warning"
}

export enum ErrorCode {
  // 通用错误
  VALIDATION_ERROR = "VALIDATION_ERROR",
  AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED",
  AUTHORIZATION_FAILED = "AUTHORIZATION_FAILED",
  RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND",
  INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
  
  // 业务错误
  INVALID_DATE_FORMAT = "INVALID_DATE_FORMAT",
  DATA_NOT_FOUND = "DATA_NOT_FOUND",
  PREDICTION_FAILED = "PREDICTION_FAILED",
  USER_ALREADY_EXISTS = "USER_ALREADY_EXISTS",
  INVALID_CREDENTIALS = "INVALID_CREDENTIALS"
}

// 基础响应接口
export interface BaseResponse<T = any> {
  status: ResponseStatus;
  message: string;
  data?: T;
  error_code?: ErrorCode;
  timestamp?: string;
}

export interface SuccessResponse<T> extends BaseResponse<T> {
  status: ResponseStatus.SUCCESS;
  data: T;
}

export interface ErrorResponse extends BaseResponse<null> {
  status: ResponseStatus.ERROR;
  data: null;
  error_code: ErrorCode;
}

// 分页相关类型
export interface PaginationMeta {
  page: number;
  size: number;
  total: number;
  pages: number;
}

export interface PaginatedResponse<T> {
  items: T[];
  meta: PaginationMeta;
}

// 认证相关类型
export interface LoginRequest {
  username: string;
  password: string;
}

export interface LoginData {
  access_token: string;
  token_type: string;
  expires_in: number;
  user: UserInfo;
}

export interface UserInfo {
  id: number;
  username: string;
  role: string;
  created_at?: string;
}

// 预测相关类型
export interface PredictionData {
  date: string;
  date_formatted: string;
  prediction_values: number[];
  time_labels: string[];
  statistics: StatisticsInfo;
}

export interface DateInfo {
  value: string;
  label: string;
  formatted: string;
}

export interface AvailableDatesData {
  dates: DateInfo[];
  count: number;
  start_date?: string;
  end_date?: string;
}

export interface StatisticsInfo {
  total_energy: number;
  peak_load: number;
  valley_load: number;
  avg_load: number;
  peak_valley_diff: number;
  peak_valley_ratio: number;
  load_factor: number;
  std_dev: number;
  cv: number;
  peak_time: string;
  valley_time: string;
  data_points: number;
}

export interface HistoricalDataItem {
  date: string;
  value: string;
  data_type: string;
}

// 图表相关类型
export interface ChartDataPoint {
  time: string;
  value: number;
}

export interface ChartSeries {
  name: string;
  data: ChartDataPoint[];
  color?: string;
}

// API请求参数类型
export interface PredictionQueryParams {
  date_str: string;
}

export interface PredictionRangeParams {
  start_date: string;
  end_date: string;
}

export interface HistoricalQueryParams {
  date: string;
  type?: 'load' | 'weather';
}

export interface HistoricalRangeParams {
  start_date: string;
  end_date: string;
  type?: 'load' | 'weather';
}

// 组件状态类型
export interface LoadingState {
  loading: boolean;
  error?: string;
}

export interface PredictionPageState {
  selectedDate: string;
  predictionData: PredictionData | null;
  availableDates: DateInfo[];
  loading: LoadingState;
  statistics: StatisticsInfo | null;
}

// API响应类型别名
export type LoginResponse = SuccessResponse<LoginData>;
export type UserResponse = SuccessResponse<UserInfo>;
export type PredictionResponse = SuccessResponse<PredictionData>;
export type AvailableDatesResponse = SuccessResponse<AvailableDatesData>;
export type HistoricalDataResponse = SuccessResponse<HistoricalDataItem[]>;
export type StatisticsResponse = SuccessResponse<StatisticsInfo>;

// HTTP方法类型
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';

// API配置类型
export interface ApiConfig {
  baseURL: string;
  timeout: number;
  headers: Record<string, string>;
}

// 请求拦截器类型
export interface RequestInterceptor {
  (config: any): any;
}

// 响应拦截器类型
export interface ResponseInterceptor {
  onFulfilled?: (response: any) => any;
  onRejected?: (error: any) => any;
} 